package com.wpc.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wpc.mapper.UserwxgzhMapper;
import com.wpc.service.WxCjThreadService;

@Controller
@RequestMapping(value="/begin")
public class BeginController {

	@Value("${md5key}")
	private String md5key;
	
	@Value("${wxkeyurl}")
	private String wxkeyurl;
	
	@Value("${fdlOpt}")
	private String fdlOpt;
	
	@Value("${startYg}")
	private Integer startYg;
	
	@Value("${endYg}")
	private Integer endYg;
	
	@Value("${UID}")
	private Integer uid;
	
	@Autowired
	private UserwxgzhMapper wserwxgzhMapper;
	
	@ResponseBody
	@RequestMapping(value="/docj",method=RequestMethod.GET)
	public Map<String,Object> docj() {
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("msg", "succes!");
		List<WxCjThreadService> list = new ArrayList<WxCjThreadService>();
		WxCjThreadService thread = null;
		int gzhCount = wserwxgzhMapper.gzhCount();
		int size=gzhCount/4;
		int start=0;
		if(gzhCount>0){
			for(int i=0;i<4;i++){
				thread=new WxCjThreadService(start,start+size);
				list.add(thread);
				start=start+size;
			}
		}
		int yu = gzhCount%4;
		if(yu>0){
			thread=new WxCjThreadService(size*4,size*4+yu);
			list.add(thread);
		}
		for(WxCjThreadService serv:list){
			serv.start();
		}
		return map;
	}
}
